//
//  BeautyArticalViewController.m
//  BobNews
//
//  Created by lanou3g on 16/5/6.
//  Copyright © 2016年 liu. All rights reserved.
//

#import "BeautyArticalViewController.h"
#import "NetWorkRequestManager.h"
@interface BeautyArticalViewController ()

@end

@implementation BeautyArticalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = self.model.title;
    
    
    [self analyticalData];
}

- (void)analyticalData {
    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:webView];
    
    NSString *str = [NSString stringWithFormat:@"http://c.3g.163.com/nc/article/%@/full.html",self.docid];
    [NetWorkRequestManager requestUrl:[NSURL URLWithString:str] RequestMethod:GET Params:nil Result:^(NSData *data, NSURLResponse *response, NSError *error) {
        if (data) {
            NSLog(@"%@",[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]);
            NSMutableDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            NSDictionary *dic = jsonDic[self.docid];
            NSString *urlStr = dic[@"shareLink"];
            
            NSString *urlStr1 = dic[@"source_url"];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                if (urlStr) {
                    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr]]];
                } else {
                    [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlStr1]]];
                }
            });
            
            
        }
        
    }];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
